package br.com.pyramides.utils;

import br.com.pyramides.model.Evento;
import br.com.pyramides.model.Usuario;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

    private SessionFactory sessionFactory;

    public Session openSession() {
        if (sessionFactory == null) {
            criaSessionFactory();
        }
        return sessionFactory.openSession();
    }

    public void criaSessionFactory() {
        AnnotationConfiguration cfg = new AnnotationConfiguration();
        cfg.addAnnotatedClass(Usuario.class);
        cfg.addAnnotatedClass(Evento.class);
        sessionFactory = cfg.buildSessionFactory();
    }
}
